﻿#include "setparamwidget.h"

QSetParamWidget::QSetParamWidget(QWidget *parent) : QWidget(parent)
{
    this->setMinimumHeight(600);

    _i32FrameCnt = 0;


    InitParamConfig();

//    this->setStyleSheet("background-color:transparent;");

    InitUI();


    connect(_pParamSaveBtn,&QPushButton::clicked,this,&QSetParamWidget::onParamSaveButtonClick);
}

/**
* @brief 初始化设置的参数
* @note
*
*/
void QSetParamWidget::InitParamConfig()
{
    st_cmd_attr l_cmd_attr;
    l_cmd_attr.sName = "加速度门限";
    l_cmd_attr.i32Cmdid = 0x11;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "rpm";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 400000.0;
    l_cmd_attr.lfMinValue = 1;
    _cmdMap.insert(0,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "减速度门限";
    l_cmd_attr.i32Cmdid = 0x12;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "rpm";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 400000.0;
    l_cmd_attr.lfMinValue = 0.0;
    _cmdMap.insert(1,l_cmd_attr);
    l_cmd_attr.valueMap.clear();


    l_cmd_attr.sName = "模拟信号死区";
    l_cmd_attr.i32Cmdid = 0x21;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "mv";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000.0;
    l_cmd_attr.lfMinValue = 0.0;
    _cmdMap.insert(2,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "模拟量输入";
    l_cmd_attr.i32Cmdid = 0x22;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "mV";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 22500;
    l_cmd_attr.lfMinValue = -22500;
    l_cmd_attr.bsigned = true;
    _cmdMap.insert(3,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "模拟量偏移量";
    l_cmd_attr.i32Cmdid = 0x23;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "mV";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = -10000;
    l_cmd_attr.bsigned = true;
    _cmdMap.insert(4,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "模拟输入滤波器的滤波率";
    l_cmd_attr.i32Cmdid = 0x24;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "mV";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    _cmdMap.insert(5,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "模拟输出功能的信号源";
    l_cmd_attr.i32Cmdid = 0x25;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[1] = "I监视器的比例";
    l_cmd_attr.valueMap[2] = "速度误差(VE)";
    l_cmd_attr.valueMap[3] = "扭矩指令输出";
    l_cmd_attr.valueMap[4] = "保留";
    l_cmd_attr.valueMap[5] = "位置跟随误差(PE)";
    l_cmd_attr.valueMap[6] = "未使用";
    l_cmd_attr.valueMap[7] = "未使用";
    l_cmd_attr.valueMap[8] = "位置反馈PFB";
    l_cmd_attr.valueMap[9] = "速度控制器输出";
    _cmdMap.insert(6,l_cmd_attr);
    l_cmd_attr.valueMap.clear();


    l_cmd_attr.sName = " IN1输入端的功能";
    l_cmd_attr.i32Cmdid = 0x31;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "无功能";
    l_cmd_attr.valueMap[1] = "CW限位开关";
    l_cmd_attr.valueMap[2] = "CCW限位开关";
    l_cmd_attr.valueMap[3] = "齿轮禁用输入";
    l_cmd_attr.valueMap[4] = "齿轮屏蔽输入";
    l_cmd_attr.valueMap[5] = "齿轮A输入";
    l_cmd_attr.valueMap[6] = "齿轮B输入";
    l_cmd_attr.valueMap[7] = "触发增量移动/点动";
    l_cmd_attr.valueMap[8] = "使用第二个电流限制 (ILIM2)";
    l_cmd_attr.valueMap[9] = "将OPMODE从1切换到3";
    l_cmd_attr.valueMap[10] = "原点开关";
    l_cmd_attr.valueMap[11] = "保留";
    l_cmd_attr.valueMap[12] = "搜索机器绝对零点";
    l_cmd_attr.valueMap[13] = "触发绝对移动";
    l_cmd_attr.valueMap[14] = "二进制MIDIST/MISPEED选择代码MSB";
    l_cmd_attr.valueMap[15] = "二进制MIDIST/MISPEED选择代码LSB";
    l_cmd_attr.valueMap[16] = "保留";
    l_cmd_attr.valueMap[17] = "触发器激活禁用";
    l_cmd_attr.valueMap[18] = "控制故障继电器";
    l_cmd_attr.valueMap[19] = "保持位置";
    l_cmd_attr.valueMap[20] = "当OPMODE=1时,有效输入切换至OPMODE=4";
    l_cmd_attr.valueMap[21] = "触发增量移动";
    l_cmd_attr.valueMap[22] = "当MODMODE=1时触发增量移动,距离=(PROTARY / DIVISIONS)";
    l_cmd_attr.valueMap[23] = "当 MODMODE=1时触发增量移动,距离=(2 * PROTARY / DIVISIONS)";
    l_cmd_attr.valueMap[24] = "使用数字输入将OPMODE8更改为OPMODE4";
    l_cmd_attr.valueMap[25] = "从 0过渡到1时，如果REMOTE=0或SWEN=0，故障将被清除";
    _cmdMap.insert(7,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = " IN2输入端的功能";
    l_cmd_attr.i32Cmdid = 0x32;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "无功能";
    l_cmd_attr.valueMap[1] = "CW限位开关";
    l_cmd_attr.valueMap[2] = "CCW限位开关";
    l_cmd_attr.valueMap[3] = "齿轮禁用输入";
    l_cmd_attr.valueMap[4] = "齿轮屏蔽输入";
    l_cmd_attr.valueMap[5] = "齿轮A输入";
    l_cmd_attr.valueMap[6] = "齿轮B输入";
    l_cmd_attr.valueMap[7] = "触发增量移动/点动";
    l_cmd_attr.valueMap[8] = "使用第二个电流限制 (ILIM2)";
    l_cmd_attr.valueMap[9] = "将OPMODE从1切换到3";
    l_cmd_attr.valueMap[10] = "原点开关";
    l_cmd_attr.valueMap[11] = "保留";
    l_cmd_attr.valueMap[12] = "搜索机器绝对零点";
    l_cmd_attr.valueMap[13] = "触发绝对移动";
    l_cmd_attr.valueMap[14] = "二进制MIDIST/MISPEED选择代码MSB";
    l_cmd_attr.valueMap[15] = "二进制MIDIST/MISPEED选择代码LSB";
    l_cmd_attr.valueMap[16] = "保留";
    l_cmd_attr.valueMap[17] = "触发器激活禁用";
    l_cmd_attr.valueMap[18] = "控制故障继电器";
    l_cmd_attr.valueMap[19] = "保持位置";
    l_cmd_attr.valueMap[20] = "当OPMODE=1时,有效输入切换至OPMODE=4";
    l_cmd_attr.valueMap[21] = "触发增量移动";
    l_cmd_attr.valueMap[22] = "当MODMODE=1时触发增量移动,距离=(PROTARY / DIVISIONS)";
    l_cmd_attr.valueMap[23] = "当 MODMODE=1时触发增量移动,距离=(2 * PROTARY / DIVISIONS)";
    l_cmd_attr.valueMap[24] = "使用数字输入将OPMODE8更改为OPMODE4";
    l_cmd_attr.valueMap[25] = "从 0过渡到1时，如果REMOTE=0或SWEN=0，故障将被清除";
    _cmdMap.insert(8,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = " IN3输入端的功能";
    l_cmd_attr.i32Cmdid = 0x33;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "无功能";
    l_cmd_attr.valueMap[1] = "CW限位开关";
    l_cmd_attr.valueMap[2] = "CCW限位开关";
    l_cmd_attr.valueMap[3] = "齿轮禁用输入";
    l_cmd_attr.valueMap[4] = "齿轮屏蔽输入";
    l_cmd_attr.valueMap[5] = "齿轮A输入";
    l_cmd_attr.valueMap[6] = "齿轮B输入";
    l_cmd_attr.valueMap[7] = "触发增量移动/点动";
    l_cmd_attr.valueMap[8] = "使用第二个电流限制 (ILIM2)";
    l_cmd_attr.valueMap[9] = "将OPMODE从1切换到3";
    l_cmd_attr.valueMap[10] = "原点开关";
    l_cmd_attr.valueMap[11] = "保留";
    l_cmd_attr.valueMap[12] = "搜索机器绝对零点";
    l_cmd_attr.valueMap[13] = "触发绝对移动";
    l_cmd_attr.valueMap[14] = "二进制MIDIST/MISPEED选择代码MSB";
    l_cmd_attr.valueMap[15] = "二进制MIDIST/MISPEED选择代码LSB";
    l_cmd_attr.valueMap[16] = "保留";
    l_cmd_attr.valueMap[17] = "触发器激活禁用";
    l_cmd_attr.valueMap[18] = "控制故障继电器";
    l_cmd_attr.valueMap[19] = "保持位置";
    l_cmd_attr.valueMap[20] = "当OPMODE=1时,有效输入切换至OPMODE=4";
    l_cmd_attr.valueMap[21] = "触发增量移动";
    l_cmd_attr.valueMap[22] = "当MODMODE=1时触发增量移动,距离=(PROTARY / DIVISIONS)";
    l_cmd_attr.valueMap[23] = "当 MODMODE=1时触发增量移动,距离=(2 * PROTARY / DIVISIONS)";
    l_cmd_attr.valueMap[24] = "使用数字输入将OPMODE8更改为OPMODE4";
    l_cmd_attr.valueMap[25] = "从 0过渡到1时，如果REMOTE=0或SWEN=0，故障将被清除";
    _cmdMap.insert(9,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "IN1用户反转的功能";
    l_cmd_attr.i32Cmdid = 0x34;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "用户输入未反转";
    l_cmd_attr.valueMap[1] = "用户输入反转";
    _cmdMap.insert(10,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "IN2用户反转的功能";
    l_cmd_attr.i32Cmdid = 0x35;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "用户输入未反转";
    l_cmd_attr.valueMap[1] = "用户输入反转";
    _cmdMap.insert(11,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "IN3用户反转的功能";
    l_cmd_attr.i32Cmdid = 0x35;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 1;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "用户输入未反转";
    l_cmd_attr.valueMap[1] = "用户输入反转";
    _cmdMap.insert(12,l_cmd_attr);
    l_cmd_attr.valueMap.clear();


    l_cmd_attr.sName = "电机连续额定电流";
    l_cmd_attr.i32Cmdid = 0x41;
    l_cmd_attr.lfCoeff = 10.0;
    l_cmd_attr.sUnit = "A";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 175;
    l_cmd_attr.lfMinValue = 0.1;
    _cmdMap.insert(13,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "电机峰值电流";
    l_cmd_attr.i32Cmdid = 0x42;
    l_cmd_attr.lfCoeff = 10.0;
    l_cmd_attr.sUnit = "A";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 350;
    l_cmd_attr.lfMinValue = 0.3;
    _cmdMap.insert(14,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "寻零电流";
    l_cmd_attr.i32Cmdid = 0x43;
    l_cmd_attr.lfCoeff = 10.0;
    l_cmd_attr.sUnit = "%";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 100;
    l_cmd_attr.lfMinValue = 0;
    _cmdMap.insert(15,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "模拟电流比例因子";
    l_cmd_attr.i32Cmdid = 0x44;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 10000;
    l_cmd_attr.lfMinValue = 100;
    _cmdMap.insert(16,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "电机最大推荐速度";
    l_cmd_attr.i32Cmdid = 0x51;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 32767;
    l_cmd_attr.lfMinValue = 10;
    _cmdMap.insert(17,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "电机额定速度";
    l_cmd_attr.i32Cmdid = 0x52;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 32767;
    l_cmd_attr.lfMinValue = 300;
    _cmdMap.insert(18,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "电机额定速度";
    l_cmd_attr.i32Cmdid = 0x53;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 32767;
    l_cmd_attr.lfMinValue = 10;
    _cmdMap.insert(19,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "模拟速度比例因子";
    l_cmd_attr.i32Cmdid = 0x54;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 32767;
    l_cmd_attr.lfMinValue = 10;
    _cmdMap.insert(20,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "速度反馈滤波";
    l_cmd_attr.i32Cmdid = 0x55;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 32767;
    l_cmd_attr.lfMinValue = 10;
    l_cmd_attr.valueMap[0] = "禁止";
    l_cmd_attr.valueMap[1] = "使能";
    _cmdMap.insert(21,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "电机极数";
    l_cmd_attr.i32Cmdid = 0x61;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 80;
    l_cmd_attr.lfMinValue = 2;
    _cmdMap.insert(22,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "电气零位";
    l_cmd_attr.i32Cmdid = 0x62;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 360;
    l_cmd_attr.lfMinValue = 0;
    _cmdMap.insert(23,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "旋转方向";
    l_cmd_attr.i32Cmdid = 0x63;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 360;
    l_cmd_attr.lfMinValue = 0;
    l_cmd_attr.valueMap.clear();
    l_cmd_attr.valueMap[0] = "逆时针正";
    l_cmd_attr.valueMap[1] = "顺时针正";
    _cmdMap.insert(24,l_cmd_attr);
    l_cmd_attr.valueMap.clear();

    l_cmd_attr.sName = "驱动器的操作模式";
    l_cmd_attr.i32Cmdid = 0x71;
    l_cmd_attr.lfCoeff = 1.0;
    l_cmd_attr.sUnit = "";
    l_cmd_attr.i32Valuelen = 1;
    l_cmd_attr.lfMaxValue = 360;
    l_cmd_attr.lfMinValue = 0;
    l_cmd_attr.valueMap[0] = "串口速度环";
    l_cmd_attr.valueMap[1] = "模拟速度环";
    l_cmd_attr.valueMap[2] = "串口转矩";
    l_cmd_attr.valueMap[3] = "模拟转矩";
    l_cmd_attr.valueMap[4] = "脉冲跟随";
    l_cmd_attr.valueMap[8] = "位置环";
    _cmdMap.insert(25,l_cmd_attr);
    l_cmd_attr.valueMap.clear();


}
/**
* @brief
* @note
*
*/
 void QSetParamWidget::InitUI()
 {

    QGridLayout* playout = new QGridLayout(this);

    int nRow = 0;

//    playout->addItem(new QSpacerItem(10,20,QSizePolicy::Minimum,QSizePolicy::Maximum),nRow,0,1,7);

//    nRow++;
    playout->addWidget(createParamSetWidget(),nRow,0,1,7);
    nRow++;
 }



 /**
* @brief
* @note
*
*/
QWidget* QSetParamWidget::createParamSetWidget()
{
    _pParamSaveBtn = new QPushButton("保存参数",this);
    QUIQss::setBtnQss(_pParamSaveBtn,"#1ABC9C", "#000000", "#2EE1C1", "#E6F8F5", "#16A086", "#A7EEE6");

    //参数设置
    _pParamSetWidget = new QTableWidget(this);

    QString sTableStyle = "QTableWidget{selection-color:rgb(0,0,0);gridline-color: rgb(150, 150, 150);border:0px solid;border-top:1px solid rgb(150, 150, 150);";
    sTableStyle = sTableStyle + "font-size:20px;font-family: 'Microsoft YaHei';color:rgb(0,0,0);}";
    sTableStyle = sTableStyle + "QTableWidget::Item{border:0px solid rgb(150, 150, 150);border-bottom:1px solid rgb(150, 150, 150);}";
    _pParamSetWidget->setStyleSheet(sTableStyle);
    _pParamSetWidget->setShowGrid(false);
//    _pParamSetWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //垂直滚动条

    QStringList sHeaderlist;
    sHeaderlist<<"参数名"<<"当前值"<<""<<"设定值"<<"";
    _pParamSetWidget->setColumnCount(sHeaderlist.size());
    _pParamSetWidget->setHorizontalHeaderLabels(sHeaderlist);
//    _pParamSetWidget->horizontalHeader()->setHidden(true);
//    _pParamSetWidget->horizontalHeader()->setStretchLastSection(true);//最后一列充满
    _pParamSetWidget->verticalHeader()->hide();
    _pParamSetWidget->setRowCount(_cmdMap.size());
    _pParamSetWidget->setColumnWidth(0,300);
    _pParamSetWidget->setColumnWidth(1,300);
    _pParamSetWidget->setColumnWidth(3,300);



//    _pParamSetWidget->setColumnHidden(2,true);

    int l_i32RowIndex = 0;
    for(int i = 0; i < _cmdMap.keys().size();i++)
    {
        int  l_key = _cmdMap.keys()[i];

        QString sName = _cmdMap[l_key].sName;

        _cmdMap[l_key].i32RowIndex = l_i32RowIndex;

        _pParamSetWidget->setRowHeight(l_i32RowIndex,40);

        if(_cmdMap[l_key].sUnit != "")
        {
            _pParamSetWidget->setItem(l_i32RowIndex,0,new QTableWidgetItem(sName+QString("(%1)").arg(_cmdMap[l_key].sUnit)));
        }
        else
        {
            _pParamSetWidget->setItem(l_i32RowIndex,0,new QTableWidgetItem(sName));
        }

        _pParamSetWidget->item(l_i32RowIndex,0)->setFlags(Qt::ItemIsEnabled);

        _pParamSetWidget->setItem(l_i32RowIndex,1,new QTableWidgetItem("0.0"));
        _pParamSetWidget->item(l_i32RowIndex,1)->setFlags(Qt::ItemIsEnabled);
        QPushButton* pbutton1 = new QPushButton("查询",this);
        pbutton1->setStyleSheet(
                    "QPushButton{padding:5px;border-radius:5px;color:rgb(255,255,255);font-size:18px;font-family: 'Microsoft YaHei';background-color: rgb(46,97,186);}"
                    "QPushButton:hover{padding:5px;border-radius:5px;color:white;font-size:18px;font-family: 'Microsoft YaHei';background-color: rgb(96,131,203);}"
                    "QPushButton:pressed{padding:5px;border-radius:5px;color:white;font-size:18px;font-family: 'Microsoft YaHei';background-color: rgb(139,165,217);}"
                    "QPushButton:disabled { background-color: rgb(200,200,200);color:black;}"
                                    );
        connect(pbutton1,&QPushButton::clicked,this,&QSetParamWidget::onGetParamButtonClick);
        _pParamSetWidget->setCellWidget(l_i32RowIndex,2,pbutton1);


        if(_cmdMap[l_key].valueMap.size() == 0)
        {
            QLineEdit* plineedit = new QLineEdit("0.0",_pParamSetWidget);
            QUIQss::setTxtQss(plineedit, "#DCE4EC", "#1ABC9C");

//            plineedit->setStyleSheet("border:1px solid;font-size:20px;font-family: 'Microsoft YaHei';QToolTip{font-size:12px;width:1024; height:40;}");
            plineedit->setToolTip(QString("范围:[%1,%2]").arg(_cmdMap[l_key].lfMinValue).arg(_cmdMap[l_key].lfMaxValue));
            _pParamSetWidget->setCellWidget(l_i32RowIndex,3,plineedit);


        }
        else
        {
            QComboBox* pComBox = new QComboBox(_pParamSetWidget);
            QList<int> l_keylist = _cmdMap[l_key].valueMap.keys();
            for(int i = 0; i < l_keylist.size();i++)
            {
                int l_valuekey = l_keylist[i];
                pComBox->addItem(_cmdMap[l_key].valueMap[l_valuekey]);
            }
            _pParamSetWidget->setCellWidget(l_i32RowIndex,3,pComBox);
        }


        _pParamSetWidget->item(l_i32RowIndex,0)->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
        _pParamSetWidget->item(l_i32RowIndex,1)->setTextAlignment(Qt::AlignCenter);

        QPushButton* pbutton = new QPushButton("设置",this);
        pbutton->setStyleSheet(
                    "QPushButton{padding:5px;border-radius:5px;color:rgb(255,255,255);font-size:18px;font-family: 'Microsoft YaHei';background-color: rgb(46,97,186);}"
                    "QPushButton:hover{padding:5px;border-radius:5px;color:white;font-size:18px;font-family: 'Microsoft YaHei';background-color: rgb(96,131,203);}"
                    "QPushButton:pressed{padding:5px;border-radius:5px;color:white;font-size:18px;font-family: 'Microsoft YaHei';background-color: rgb(139,165,217);}"
                    "QPushButton:disabled { background-color: rgb(200,200,200);color:black;}"
                                    );
        connect(pbutton,&QPushButton::clicked,this,&QSetParamWidget::onSetParamButtonClick);
        _pParamSetWidget->setCellWidget(l_i32RowIndex,4,pbutton);

        _pParamSetWidget->setRowHeight(l_i32RowIndex,50);


        l_i32RowIndex = l_i32RowIndex +1;
    }


    QWidget* pwidget = new QWidget(this);
    QGridLayout* playout = new QGridLayout(pwidget);

    playout->addWidget(_pParamSetWidget,0,0,1,9);
    playout->addWidget(_pParamSaveBtn,1,4,1,1);

    playout->setRowStretch(0,4);
    playout->setRowStretch(1,1);

    return pwidget;
}

/**
* @brief
* @note
*
*/
void QSetParamWidget::onSetParamButtonClick()
{
    QPushButton *pushButton = dynamic_cast<QPushButton*>(this->sender());
    if(pushButton == nullptr)
    {
        return;
    }
    int x = pushButton->frameGeometry().x();
    int y = pushButton->frameGeometry().y();
    QModelIndex index = _pParamSetWidget->indexAt(QPoint(x, y));
    int row = index.row();

     st_cmd_attr l_cmd_attr;
     l_cmd_attr.i32RowIndex = -1;
    for(int i = 0; i <  _cmdMap.keys().size();i++)
    {
        int l_key = _cmdMap.keys()[i];
        if(_cmdMap[l_key].i32RowIndex == row)
        {
            l_cmd_attr = _cmdMap[l_key];
            break;
        }
    }

    if(l_cmd_attr.i32RowIndex == -1)
    {
        return;
    }

    //获取当前命令的属性值
    int l_cmd_id = l_cmd_attr.i32Cmdid;

    if(l_cmd_attr.valueMap.size() == 0)
    {
        float lfValue =((QLineEdit*)_pParamSetWidget->cellWidget(l_cmd_attr.i32RowIndex,3))->text().toFloat();
        fourchar l_currentvalue;
        l_currentvalue.i32data = lfValue*l_cmd_attr.lfCoeff;

        if(lfValue > l_cmd_attr.lfMaxValue || lfValue < l_cmd_attr.lfMinValue)
        {
            QMessageBox *msgBox = new QMessageBox();
            msgBox->setWindowTitle("提示");
            msgBox->setText(QString("输入数据有误，有效范围为[%1,%2]").arg(l_cmd_attr.lfMinValue).arg(l_cmd_attr.lfMaxValue));
            msgBox->addButton("确定", QMessageBox::AcceptRole);
            msgBox->setStyleSheet("font-size:18px;font-family: 'Microsoft YaHei';background-color:white");
            msgBox->exec();
            delete msgBox;
            return;
        }

        emit signal_set_thresholdparam(_i32AixsNo,l_cmd_id,l_currentvalue.i32data,l_cmd_attr.i32Valuelen);
    }
    else
    {
        QComboBox* pComboBox = (QComboBox*)_pParamSetWidget->cellWidget(l_cmd_attr.i32RowIndex,3);

        QString sValue = pComboBox->currentText();
        int l_data = l_cmd_attr.valueMap.key(sValue);
        fourchar l_currentvalue;
        l_currentvalue.i32data = l_data;
        emit signal_set_thresholdparam(_i32AixsNo,l_cmd_id,l_currentvalue.i32data,l_cmd_attr.i32Valuelen);
    }
}

/**
* @brief
*
**/
void QSetParamWidget::onGetParamButtonClick()
{
    QPushButton *pushButton = dynamic_cast<QPushButton*>(this->sender());
    if(pushButton == nullptr)
    {
        return;
    }
    int x = pushButton->frameGeometry().x();
    int y = pushButton->frameGeometry().y();
    QModelIndex index = _pParamSetWidget->indexAt(QPoint(x, y));
    int row = index.row();

     st_cmd_attr l_cmd_attr;
     l_cmd_attr.i32RowIndex = -1;
    for(int i = 0; i <  _cmdMap.keys().size();i++)
    {
        int l_key = _cmdMap.keys()[i];
        if(_cmdMap[l_key].i32RowIndex == row)
        {
            l_cmd_attr = _cmdMap[l_key];
            break;
        }
    }

    if(l_cmd_attr.i32RowIndex == -1)
    {
        return;
    }

    //获取当前命令的属性值
    int l_cmd_id = l_cmd_attr.i32Cmdid;

    emit signal_get_thresholdparam(_i32AixsNo,l_cmd_id);
}


void QSetParamWidget::setButtonStyleSheet(QPushButton* pBtn)
{
    pBtn->setStyleSheet(
                "QPushButton:checked { background-color: rgb(245,90,70);;color:white;}"
                "QPushButton:unchecked { background-color: rgb(200,200,200);;color:black;}"
                "QPushButton{background-color: rgb(200,200,200);padding:5px;border-radius:5px;color:black;"
                "font-size:18px;font-family: 'Microsoft YaHei';}"
                "QPushButton:disabled { background-color: rgb(200,200,200);color:black;}"

                                );


//    pBtn->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    pBtn->setMinimumHeight(20);
}

/**
* @brief
*
**/
void QSetParamWidget::onParamSaveButtonClick()
{
    emit signal_set_thresholdparam(_i32AixsNo,0xEE,0x0,0x01);
}


/**
* @brief
*
**/
void QSetParamWidget::onRcvData(QVariant var)
{
    st_thresholdParam l_param = var.value<st_thresholdParam>();
    _rcv_capdata = l_param;
    if(l_param.datatype != 0x14)
    {
        return;
    }

    uchar cmdid = l_param.cmdid;

    fourchar l_data;
    l_data.data[0] = l_param.data[3];
    l_data.data[1] = l_param.data[2];
    l_data.data[2] = l_param.data[1];
    l_data.data[3] = l_param.data[0];

    //显示当前值
    for(int i = 0; i <  _cmdMap.keys().size();i++)
    {
        int l_key = _cmdMap.keys()[i];
        if(_cmdMap[l_key].i32Cmdid == cmdid)
        {
            if(_cmdMap[l_key].valueMap.size() == 0)
            {
                if(_cmdMap[l_key].bsigned == true)
                {
                    _pParamSetWidget->item(_cmdMap[l_key].i32RowIndex,1)->setText(QString::number(l_data.i32data));
                }
                else
                {
                    _pParamSetWidget->item(_cmdMap[l_key].i32RowIndex,1)->setText(QString::number(l_data.ui32data));
                }
            }
            else
            {
                _pParamSetWidget->item(_cmdMap[l_key].i32RowIndex,1)->setText(_cmdMap[l_key].valueMap.value(l_data.i32data,"未知"));
            }
        }
    }
}
